"""自定义异常2应用"""


class EnemyError(Exception):
    """自定义异常"""

    def __init__(self, message, error_line, atk, serial):
        self.message = message
        self.error_line = error_line
        self.atk = atk
        self.serial = serial


class Enemy:
    def __init__(self, name, atk):
        self.name = name
        self.atk = atk

    @property
    def name(self):
        return self.__name

    @name.setter
    def name(self, value):
        self.__name = value

    @property
    def atk(self):
        return self.__atk

    @atk.setter
    def atk(self, value):
        if 0 <= value <= 100:
            self.__atk = value
        else:
            raise EnemyError(f"{value}:输入的攻击力不符合.", "错误在32行！", value, "编号为：100")

    def __str__(self):
        return f"敌人{self.__name}, 攻击力为：{self.__atk}"


# 捕捉异常
if __name__ == "__main__":
    try:
        zs = Enemy('张三', 100)
        print(zs)
    except EnemyError as e:
        print(e)

